# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
    def __str__(self):
        return str(self.val)
class Solution:
    def oddEvenList(self, head: ListNode) -> ListNode:
        if head is None or head.next is None:
            return head
        even = evenHead = head.next
        odd = head
        while even:
            odd.next = even.next
            even.next = None
            if odd.next:
                odd = odd.next
                even.next = odd.next
                even = even.next
            else:
                even = None
        odd.next = evenHead
        return head

def buildListNode(nodes):
    print(nodes)
    a = []
    for val in nodes:
        a.append(ListNode(val))

    for i in range(len(a) - 1):
        a[i].next = a[i + 1]
    return a[0]

if __name__ == '__main__':
    so = Solution()
    n =  [1,2,3,4,5,6]
    head = buildListNode(n)
    r = so.oddEvenList(head)
    print(r)
